﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHospital.BLL;
namespace MyHospital.web
{
    public partial class BookOfDis : System.Web.UI.Page
    {
        BookService bookService = new BookService();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["PatientID"] == null)
            {
                Response.Write("<script>alert('未登录，请先登录！');window.location.href='Login.aspx';</script>");
            }
            GridView1.DataSource = bookService.showDis();
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = bookService.findDis(inp1.Value);
            GridView1.DataBind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            if (GridView1.PageCount > 5)
            {
                GridView1.PageIndex = e.NewPageIndex;
                GridView1.DataSource = bookService.showDis();
                GridView1.DataBind();
            }
            else
            {
                GridView1.PageIndex = e.NewPageIndex;
                GridView1.DataSource = bookService.findDis(inp1.Value);
                GridView1.DataBind();
            }

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            GridViewRow row = btn.Parent.Parent as GridViewRow;
            String disName = row.Cells[0].Text;//获得疾病名称
            DataList1.DataSource = bookService.doctorShow(disName);
            DataList1.DataBind();
        }
        protected void ImageButton1_Command(object sender, CommandEventArgs e)
        {
            int id = (int.Parse)(e.CommandArgument.ToString());
            Session["doctorId"] = id;
            Response.Redirect("Booking2.aspx");
        }

        protected void ImageButton1_Command1(object sender, CommandEventArgs e)
        {
            int id = (int.Parse)(e.CommandArgument.ToString());
            if (inp2.Value.ToString() == "请选择就诊日期")
            {
                Response.Write("<script>alert('请选择就诊日期！');window.location.href='BookOfDepart.aspx';</script>");
            }
            else
            {
                Session["date"] = inp2.Value;
                Session["doctorId"] = id;
                Response.Redirect("BookEnd.aspx");
            }
            
        }
    }
}